package cn.buk.qms.performance;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class LogRequestAspect {

  private static final  Logger logger = LoggerFactory.getLogger(LogRequestAspect.class);

  @Pointcut("execution(public * cn.buk.qms.service.*.*(..))")
  public void log() {

  }

  @Before("log()")
  public void doBefore(JoinPoint joinPoint) {
//    System.out.println("aop doBefore..");
//    logger.info("aop doBefore.." + joinPoint.toString());
//    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
//    HttpServletRequest request = attributes.getRequest();
//
//    //url
//    logger.info("url={}",request.getRequestURI());
//
//    //method
//    logger.info("method={}", request.getMethod());
//
//    //ip
//    logger.info("ip={}", request.getRemoteAddr());
//
//    //类方法
//    logger.info("classMethod={}", joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName());
//
//    //参数
//    Enumeration<String> paramter = request.getParameterNames();
//    while (paramter.hasMoreElements()) {
//      String str = (String) paramter.nextElement();
//      logger.info(str + "={}", request.getParameter(str));
//    }

  }

  @After("log()")
  public void doAfter() {
//    logger.info("aop doAfter");
  }
}
